#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 30;
int a[N];
bool b[N];
int t, n;
ll ans = 0;
map <int, int> mp;

void check(){
    ll cm = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = i-1; j >= 1; --j){
            if (b[i] == b[j]){
                if (a[i] == a[j]) cm += a[j];
                break;
            }
        }
    }
    ans = max(ans, cm);
}

void fx(int bit){
    if (bit > n){
        check();
        return;
    }
    b[bit] = 1;
    fx(bit+1);
    b[bit] = 0;
    fx(bit+1);
}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> t;
    while (t--){
        ans = 0;
        cin >> n;
        if (n > 20) return 0;
        for (int i = 1; i <= n; ++i) cin >> a[i];
        fx(1);
        cout << ans << endl;
    }
    return 0;
}
